package cn.wolfcode.luowowo.small.service;

import cn.wolfcode.luowowo.small.domin.UserCoin;
import cn.wolfcode.luowowo.small.mapper.UserCoinMapper;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class UserCoinServiceImpl implements IUserCoinService{
    @Autowired
    private UserCoinMapper userCoinMapper;
    @Override
    public UserCoin queryByUserId(Long id) {
        UserCoin userCoin=userCoinMapper.getByUserId(id);
        return userCoin;
    }

    @Override
    public void updateByUserCoin(UserCoin userCoin) {
        long goldsIds = userCoinMapper.getByUserId(userCoin.getUserId()).getGoldsIds();

        if(goldsIds==userCoin.getGoldsIds()){
            userCoinMapper.updateUserCoin(userCoin);
        }else {

            userCoinMapper.insert(userCoin);
        }

    }

    @Override
    public void insert(UserCoin userCoin) {
        userCoinMapper.insert(userCoin);
    }
}
